package com.hc.jdbc.Dao;

import com.hc.jdbc.entity.User;
import com.hc.jdbc.util.BaseDao;

import java.sql.SQLException;
import java.util.List;

public class UserDao extends BaseDao {
    /**
     * 查询所有用户
     */
    public List<User> getAllUser() throws Exception {
        String sql = "select * from t_user";
        List<User> userList = executeQuery(User.class, sql);
        return userList;
    }

    /**
     * 登录
     */
    public User getUser(String account, String password) throws Exception {
        String sql = "select * from t_user where account=? and password=?";
        List<User> userList = executeQuery(User.class, sql, account, password);
        if (!userList.isEmpty()) {
           return userList.get(0);
        }
        return null;
    }
}

//测试类
class Test {
    public static void main(String[] args) throws Exception {
        UserDao userDao = new UserDao();
        List<User> userList = userDao.getAllUser();
        System.out.println(userList);
    }
}
